<!--#include file="pjson.asp"-->
<!DOCTYPE html>
<html>
<head>
  <title>类型管理</title>
<%
easp.include "h.asp"
%>
</head>
<body>
<%
dim tn
tn="typ"
' t_define
%>
  <div class="layui-fluid">
    <div class="layui-card"><br>
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">检索</label>
            <div class="layui-input-block">
              <input type="text" name="<%=tn%>_search" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="<%=tn%>_search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
 			  <button type="button" class="layui-btn" lay-submit lay-filter="<%=tn%>_add">新增工单类型</button>			
         </div>
        </div>
      </div>

      <div class="layui-card-body">
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="<%=tn%>_edit">修改</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="<%=tn%>_del">删除</a>			
		</script>
		<table id="<%=tn%>" lay-filter="<%=tn%>"></table><br>
      </div>
    </div>
  </div>
  <script src="/<%=rootpath%>/src/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '/<%=rootpath%>/src/layuiadmin/'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,admin = layui.admin	
    ,table = layui.table;
    form.render();
	table.render({
        elem: '#<%=tn%>',
        url: 'pjson.asp?action=<%=tn%>_l',
        cols: [[
		{type:'checkbox'},		
        {field: 'id',title: 'ID',width: 60,sort: true,hide:false},
        <%g_tbf "name1","工单类型"%>
        {fixed: 'right',width: 200,align: 'center',toolbar: '#barDemo'}]],
        id: '<%=tn%>',
        limit: 10,
        page: true,
        height: 475
    });
    form.on('submit(equipmentName_hand)', function(data){
		$(location).attr('href',"equipmentType_l.asp");  
    });		
    form.on('submit(<%=tn%>_search)', function(data){
      var field = data.field;
      table.reload('<%=tn%>', {
        where: field
      });
            layer.msg('已刷新');	  
    });	
    form.on('submit(<%=tn%>_add)', function(data){
      layer.open({
        type: 2,title: '新增',content: '<%=tn%>_frm.asp?now=' + new Date().getTime() +"&type=<%=tn%>",maxmin: true
        ,area: ['500px', '450px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submitID = 'LAY-user-front-submit'
          ,submit = layero.find('iframe').contents().find('#'+ submitID);
          iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
            var field = data.field; 
				$.post('pjson.asp?now=' + new Date().getTime(), {
					action: "<%=tn%>_add",
					field
				},
				function(data) {
					layer.msg(data);
				});
            table.reload('<%=tn%>'); 
            layer.close(index); 
          });  
          submit.trigger('click');
        }
        ,success: function(layero, index){
        }
      });	
    });	
	
    table.on('tool(<%=tn%>)',
    function(obj) {
        var data = obj.data;
		if (obj.event === '<%=tn%>_edit') {
			var _this = $(this);
			  layer.open({
				type: 2
				,title: '修改'
				,content: '<%=tn%>_frm.asp?now=' + new Date().getTime()+"&id="+data.id
				,maxmin: true
				,area: ['500px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data2){
					var field = data2.field; 
						$.post('pjson.asp?now=' + new Date().getTime(), {
							action: "<%=tn%>_upd",id:data.id,
							field
						},
						function(data) {
							layer.msg(data);
						});
					table.reload('<%=tn%>'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){
				}
				});				
			table.reload('<%=tn%>');
		}		
		else if (obj.event === '<%=tn%>_del') {
			var _this = $(this);
			layer.confirm('您确定删除此信息？' + data.id, {
				icon: 3,
				title: '提示信息'
			},
			function(index) {
				$.post('pjson.asp?now=' + new Date().getTime(), 
				{
					id: data.id
					,action: "<%=tn%>_del"
				},
				function(data) {
					if (data.code == 0) {
						layer.msg("成功!!");
					} else {
						layer.msg("失败！！ "+data);
					}
				});
				layer.close(index);
				table.reload('<%=tn%>');				
			});
		}	
	});		
  });
  </script>
</body>
</html>